package com.mxf.code.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author banmoon
 */
public interface ChildrenTree<T> {

    void setChildren(List<T> children);

    List<T> getChildren();


    /**
     * 添加子集，如果已经有了，则不添加
     *
     * @param t the t
     */
    default void add(T t) {
        List<T> children = getChildren();
        if (Objects.isNull(children)) {
            children = new ArrayList<>();
            setChildren(children);
        }
        if (!children.contains(t)) {
            children.add(t);
        }
    }

}
